<template>
	<view class="page tn-safe-area-inset-bottom" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
		<view class="top-bg"></view>
		<dawnBar title="医生信息"></dawnBar>
		<view class="page-container">
			<view class="" v-if="resultData.id">

				<view class="list tn-margin-bottom-sm">

					<view class="list-item tn-flex tn-flex-col-center">
						<view class="tn-flex tn-flex-col-center"
							@click="navLink('/hosp/doctor/detail?itemId='+resultData.id)">
							<image mode="widthFix" class="doctor-image" :src="resultData.headImageUrl">
						</view>
						<view style="width: 100%;" class="list-content tn-flex tn-flex-col-center tn-flex-row-between">
							<view class="tn-padding-left-ss" style="width: 100%;">
								<view class=" tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-between">
									<view @click="navLink('/hosp/doctor/detail?itemId='+resultData.id)"
										class="tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-between">
										<text
											class="dawn-text-md tn-text-bold tn-color-dawn">{{resultData.name || '' }}</text>
										<text class="tn-color-gray tn-padding-left-xs tn-padding-right-xs">|</text>
										<tn-tag class="dawn-tag-sm dawn-tag-sm__1">{{resultData.gender || '' }}</tn-tag>
									</view>
									<view>
										<view class="justify-content-item ">
											<tn-tag backgroundColor="tn-main-gradient-dawn" fontColor="#FFFFFF"
												shape="circleLeft" width="auto">
												{{ resultData.jobTitle || ''}}
											</tn-tag>
										</view>
									</view>
								</view>
								<view class="">
									<text class="tn-icon-organizatio-fill dawn-text-sm tn-margin-right-ss"></text>
									<text class="dawn-text-sm">{{ dept.name }}</text>
								</view>
								<view class="" v-if="resultData.phone">
									<text class="tn-icon-phone-fill dawn-text-sm tn-margin-right-ss"></text>
									<text class="dawn-text-sm">{{ resultData.phone }}</text>
								</view>
								<view class="" v-if="resultData.workRange">
									<text class="tn-icon-time-fill dawn-text-sm tn-margin-right-ss"></text>
									<text class="dawn-text-sm">{{ resultData.workRange }}</text>
								</view>
								<view class="">
									<text class="tn-icon-map-fill dawn-text-sm tn-margin-right-ss"></text>
									<text class="dawn-text-sm">{{ resultData.address || dept.address }}</text>
								</view>

							</view>
						</view>

						<!-- <view class="">
						<text class="tn-text-sm dawn-color-grey">{{ resultData.tags }}</text>
					</view> -->
					</view>


				</view>


				<view class='tn-bg-white dawn-shadow dawn-radius'>
					<view class='conters'>
						<jyf-parser :html="content" ref="article" :tag-style="tagStyle" />
					</view>
				</view>
			</view>
		</view>

		<!-- loading -->
		<dawnLoading :show="loading"></dawnLoading>

		<view v-if="show">
			<dawnMsg :msg="msg"></dawnMsg>
		</view>

		<!-- 悬浮按钮-->
		<NavBtn></NavBtn>
	</view>
</template>

<script>
	import page_mixin from '@/mixins/page_mixin.js'
	import shareInfo from '@/hosp/components/shareInfo/index.vue';
	import parser from "@/hosp/components/jyf-parser/jyf-parser";
	import * as DoctorApi from '@/api/cms/doctor.js';
	import * as DepartmentApi from '@/api/cms/department.js';
	import dayjs from "@/plugin/dayjs/dayjs.min.js";
	import * as Util from '@/utils/util.js';
	import {
		mapGetters
	} from "vuex";
	const app = getApp();

	export default {
		name: 'newsDetail',
		components: {
			shareInfo,
			"jyf-parser": parser
		},
		mixins: [page_mixin],
		computed: mapGetters(['uid', 'isLogin', 'userInfo']),
		data() {
			return {
				loading: false,
				show: false,
				msg: '暂无数据',
				id: 0,
				resultData: {},
				dept: {},
				store_info: {},
				content: '',
				tagStyle: {
					img: 'width:100%;'
				},
				shareInfoStatus: false,
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			if (options.hasOwnProperty('itemId')) {
				this.id = options.itemId;
			} else {
				// #ifndef H5
				uni.navigateBack({
					delta: 1
				});
				// #endif
				// #ifdef H5
				history.back();
				// #endif
			}
		},
		onShow: function() {
			this.getData();
		},
		/**
		 * 用户点击右上角分享
		 */
		// #ifdef MP
		onShareAppMessage: function() {
			return {
				title: this.resultData.title,
				imageUrl: this.resultData.picUrl ? this.resultData.picUrl : "",
				desc: this.resultData.introduction,
				path: '/hosp/doctor/detail?itemId=' + this.id
			};
		},
		// #endif
		methods: {
			getData: function() {
				this.loading = true;
				this.show = false;
				DoctorApi.getDoctor(this.id).then(res => {
					console.table(res)
					this.loading = false;
					if (res.code === 0) {
						this.$set(this, 'resultData', res.data);
						this.getDept(res.data.departmentId);
						this.content = res.data.content;
						// #ifdef H5
						if (this.$wechat.isWeixin()) {
							this.setShareInfo();
						}
						// #endif
					} else {
						this.show = true;
						this.msg = '暂无数据';
					}
				});
				// 增加文章浏览量
				// ArticleApi.addArticleBrowseCount(this.id)
			},

			getDept: function(departmentId) {
				let that = this;
				DepartmentApi.getDepartment(departmentId).then(res => {
					console.table(res)
					this.loading = false;
					if (res.code === 0) {
						this.$set(this, 'dept', res.data);
					}
				});
				// 增加文章浏览量
				// ArticleApi.addArticleBrowseCount(this.id)
			},
			goodInfo(id) {
				ProductSpuApi.getSpuDetail(id).then(res => {
					this.$set(this, 'store_info', res.data);
				})
			},
			listenerActionSheet() {
				this.shareInfoStatus = true
			},
			setShareInfoStatus() {
				this.shareInfoStatus = false
			},
			setShareInfo: function() {
				let href = location.href;
				let configAppMessage = {
					title: this.resultData.title,
					desc: this.resultData.introduction,
					link: href,
					imgUrl: this.resultData.picUrl
				};
				this.$wechat.wechatEvevt([
					"updateAppMessageShareData",
					"updateTimelineShareData"
				], configAppMessage);
			},

			fen2yuan(price) {
				return Util.fen2yuan(price)
			},
			formatDate: function(date) {
				return dayjs(date).format("YYYY-MM-DD");
			},
			formatDateTime: function(date) {
				return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
			}
		}
	}
</script>

<style lang="scss" scoped>
	.newsDetail {
		padding: 30rpx 0;
	}

	.newsDetail .title {
		padding: 0 30rpx;
		font-size: 34rpx;
		color: #282828;
		font-weight: bold;
		line-height: 1.5;
	}

	.newsDetail .item {
		padding: 20rpx 30rpx;
		// font-size: 34rpx;
		color: #8A8B8C;
		// font-weight: bold;
		line-height: 1.5;
	}

	.newsDetail .conters {
		padding: 30rpx;
		font-size: 30rpx;
		color: #282828;
		line-height: 1.7;
	}

	.newsDetail .bnt {
		color: #fff;
		font-size: 30rpx;
		width: 690rpx;
		height: 90rpx;
		border-radius: 45rpx;
		margin: 48rpx auto;
		text-align: center;
		line-height: 90rpx;
	}

	.doctor-image {
		margin-right: 10rpx;
		width: 140rpx;
		height: 140rpx;
		border-radius: $dawn-border-radius;
	}
</style>